package com.mz.emergency.service.impl;

import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mz.emergency.domain.AdmissionAssessment;
import com.mz.emergency.mapper.AdmissionAssessmentMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

@Service
@Slf4j
@RequiredArgsConstructor
public class AdmissionAssessmentServiceImpl extends MPJBaseServiceImpl<AdmissionAssessmentMapper, AdmissionAssessment> {

    /**
     * 查询入院护理评估详情根据诊断id
     *
     * @param diagnosisId 诊断id
     * @return 入院护理评估
     */
    public AdmissionAssessment selectUnitMemberByDiagnosisId(String diagnosisId) {
        MPJLambdaWrapper<AdmissionAssessment> lambdaQueryWrapper = new MPJLambdaWrapper<>();
        lambdaQueryWrapper.selectAll(AdmissionAssessment.class);
        lambdaQueryWrapper.eq(AdmissionAssessment::getDiagnosisId, diagnosisId);
        return getOne(lambdaQueryWrapper);
    }

    /**
     * 新增入院护理评估
     *
     * @param admissionAssessment 入院护理评估
     * @return 结果
     */
    public boolean insertUnitMember(AdmissionAssessment admissionAssessment) {
        if (!admissionAssessment.getId().isEmpty()) {
            admissionAssessment.setUpdateTime(new Date());
            admissionAssessment.setUpdateBy("王强");
        } else {
            admissionAssessment.setId(String.valueOf(UUID.randomUUID()));
            admissionAssessment.setCreateTime(new Date());
            admissionAssessment.setCreateBy("张伟");
        }
        return saveOrUpdate(admissionAssessment);
    }


}
